package mspbots.liongard.client.core.app;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import mspbots.liongard.client.core.client.ClientProperties;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.validation.Valid;

/**
 * TeamsController
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/8/28
 */
@Log4j2
@RestController
@RequiredArgsConstructor
@RequestMapping("client/{tenantId}")
public class AppController {

    private final AppServiceImpl appServiceImpl;

    @InitBinder("syncRequest")
    public void initMerchantOnlyBinder(WebDataBinder binder) {
        binder.addValidators(new SyncRequest.SyncRequestValidator());
    }

    @PostMapping(path = "test")
    public Mono<Boolean> test(@PathVariable Long tenantId,@Valid @RequestBody ClientProperties properties) {
        properties.setTenantId(tenantId);
        return this.appServiceImpl.initialize(properties);
    }

    @GetMapping(path = "synchronise")
    public Mono<Object>  synchronise(@PathVariable Long tenantId, @Valid SyncRequest syncRequest) {
        return this.appServiceImpl.synchronise(tenantId, syncRequest);
    }

    @GetMapping("on-off/{onOff}")
    public Mono<Boolean> onOff(@PathVariable Long tenantId, @PathVariable String onOff) {
        return this.appServiceImpl.onOff(tenantId, onOff);
    }

}
